"""
localStorage: 永久有效
sessionStorage：窗口关闭，会话结束自动删除
cookie: 可以指定有效期，多用于存储用户信息 等
"""
import requests

# 模拟登录获取cookie
url = "https://vip.hdbz.net/auth/ajaxlogin"
data = {
    'username': '16696108895',
    'userpwd': '123456m'
}
res = requests.post(url, data=data)
if res.status_code == 200:
    # RequestsCookieJar
    print(res.cookies)

    # # 方式一 直接使用cookiejar
    # home_res = requests.get("https://vip.hdbz.net/site/FavoriteList?page=1&limit=10", cookies=res.cookies)
    # print(home_res.json())

    # 方式二 构造cookies字典
    # cookies = {
    #     "uid": res.cookies.get("uid"),
    #     "uname": res.cookies.get("uname"),
    #     "unotify": res.cookies.get("unotify"),
    # }
    # home_res = requests.get("https://vip.hdbz.net/site/FavoriteList?page=1&limit=10", cookies=res.cookies)
    # print(home_res.json())

    # 方式三 在headers中使用cookie
    # headers = {
    #     "cookie": f'uid={res.cookies.get("uid")};uname={res.cookies.get("uname")};unotify={res.cookies.get("unotify")}'
    # }
    # home_res = requests.get("https://vip.hdbz.net/site/FavoriteList?page=1&limit=10", headers=headers)
    # print(home_res.json())

# 如果不能轻松的模拟登录获取cookie， 则可以在浏览器登录之后 手动复制cookie
# 但是随着cookie过期则需要再次手动赋值
headers = {
	"cookie": f'Hm_lvt_c555701034a208b65b9f7b81d7aa331f=1743490452; HMACCOUNT=874C07378180B76A; Hm_lpvt_c555701034a208b65b9f7b81d7aa331f=1743492632; isVip=0; userNickname=16696108895; userimg=https%3A%2F%2Fvip.hdbz.net%2Favatar%2Fnoavatar.png; uname=16696108895; unotify=42a16180c46c130b9f82f0de279fdcd5; uid=18613'
}
favorite_res = requests.get("https://vip.hdbz.net/site/FavoriteList?page=1&limit=10", headers=headers)
print(favorite_res.json())


# download_res = requests.get("https://vip.hdbz.net/site/downloadlist?page=1&limit=10", headers=headers)
# print(download_res.json())